﻿using System;
using ApplicationLibrary.DBManager;

using Plumber.Masters.Reports;
using Plumber.Masters.Reports.DataSet;

namespace Plumber.Masters.Library
{
    internal class PrintEnvelope
    {
        private printerForm printerform;

        public PrintEnvelope(printerForm pf)
        {
            printerform = pf;
        }

        public void Print(string title, string description, string address, string zipcode, string city, string county)
        {
            DSEnvelope DSPrintEnv = new DSEnvelope();
            DSEnvelope.EnvelopeRow eRow = DSPrintEnv.Envelope.NewEnvelopeRow();

            string trimmedDesc = description.TrimEnd(new Char[] { '\r', '\n', '\t', ' ' });

            eRow.Name = (title != "")
                            ? string.Concat(title, "\n", trimmedDesc)
                            : trimmedDesc;

            eRow.Address = string.Concat(address, "\n", zipcode, " ", city, " ", county);

            DSPrintEnv.Envelope.AddEnvelopeRow(eRow);
            Envelope env = new Envelope();
            env.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Auto;
            env.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperEnvelopeItaly;
            env.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;

            printerform.ShowReport(env, DSPrintEnv);
        }
    }
}